<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="layout" content="bocMain"/>
    <title>进件作业系统</title>
</head>

<body>
    <header class="header-title">联系人信息</header>
    <g:form action="contactConnectPersonInfoSave" method="post" class="myForm contactInfoForm">
        <input type="hidden" name="id" id="id" value="${this?.opportunity?.id}">

        <g:set var="spouse" value="${com.next.OpportunityContact.findByOpportunityAndType(opportunity, com.next.OpportunityContactType.findByName('借款人配偶'))?.contact}"/>
        <div class="weui-cells weui-cells_form weui-label-10">
            <span style="margin-left: 5px;color: red">注：与申请人关系首选配偶和父母</span>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">联系人姓名</label></div>
                <div class="weui-cell__bd">
                    <g:textField class="weui-input" id="fullName1" name="fullName1" placeholder="请输入" value="${spouse?.fullName}"></g:textField>
                </div>
            </div>

            <div class="weui-cell weui-cell_select weui-cell_select-after">
                <div class="weui-cell__hd"><label class="weui-label">与申请人关系</label></div>
                <div class="weui-cell__bd">
                    <g:select class="weui-select" id="opportunityContactType1" name="opportunityContactType1" from="${com.next.OpportunityContactType.findAllByType('relation')}" optionKey="id" optionValue="name" noSelection="${['': '请选择']}" value="${spouse?com.next.OpportunityContactType.findByName('配偶')?.id:''}"></g:select>
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">工作单位</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" id="companyName1" name="companyName1" placeholder="请输入" />
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">联系人手机</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="number" id="cellphone1" name="cellphone1" placeholder="请输入" />
                </div>
            </div>
        </div>
        <div class="weui-cells weui-cells_form weui-label-10">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
                <div class="weui-cell__bd">
                    <g:textField class="weui-input" id="fullName2" name="fullName2" placeholder="请输入"></g:textField>
                </div>
            </div>

            <div class="weui-cell weui-cell_select weui-cell_select-after">
                <div class="weui-cell__hd"><label class="weui-label">与申请人关系</label></div>
                <div class="weui-cell__bd">
                    <g:select class="weui-select" id="opportunityContactType2" name="opportunityContactType2" from="${com.next.OpportunityContactType.findAllByType('relation')}" optionKey="id" optionValue="name" noSelection="${['': '请选择']}"></g:select>
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">工作单位</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" id="companyName2" name="companyName2" placeholder="请输入" />
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">联系人手机</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="number" id="cellphone2" name="cellphone2" placeholder="请输入" />
                </div>
            </div>
        </div>
    </g:form>

    <div class="bigBtn">
        <button type="button" class="weui-btn weui-btn_primary" id="submit">下一步</button>
    </div>

<script>

    $("#submit").click(function () {

        var fullName1 = $("#fullName1").val();
        if (!fullName1) {
            helpMessage("请输入联系人姓名");
            return;
        }

        var opportunityContactType1 = $("#opportunityContactType1").val()
        if (!opportunityContactType1) {
            helpMessage("请输入与申请人关系");
            return;
        }

        var companyName1 = $("#companyName1").val()
        if (!companyName1) {
            helpMessage("请输入工作单位");
            return;
        }

        var cellphone1 = $("#cellphone1").val()
        if (!cellphone1) {
            helpMessage("请输入联系人手机");
            return;
        }
        if (!(/^1\d{10}$/.test(cellphone1))) 
        {
            helpMessage("请输入正确的手机号");
            return;
        }

        var fullName2 = $("#fullName2").val();
        if (!fullName2) {
            helpMessage("请输入联系人姓名");
            return;
        }

        var opportunityContactType2 = $("#opportunityContactType2").val()
        if (!opportunityContactType2) {
            helpMessage("请输入与申请人关系");
            return;
        }

        var companyName2 = $("#companyName2").val()
        if (!companyName2) {
            helpMessage("请输入工作单位");
            return;
        }

        var cellphone2 = $("#cellphone2").val()
        if (!cellphone2) {
            helpMessage("请输入联系人手机");
            return;
        }
        if (!(/^1\d{10}$/.test(cellphone2))) 
        {
            helpMessage("请输入正确的手机号");
            return;
        }

        $(".myForm").submit();
    })

    function helpMessage(message) {
        $(".helpMsg").text(message).fadeIn(200);
        setTimeout(function () {
            $(".helpMsg").fadeOut(200);
        }, 2000);
    }
</script>
</body>
</html>
